
#include <iostream>
#include "single_linked_list.h"
#include "single_linked_list_test.h"

using namespace std;

/*!
 * @brief **测试-单向链表-复制构造**
 * @note
 * 测试-单向链表-复制构造
 * -------------------
 * -------------------
 *
 * -------------------
 * 声明singly_linked_list\n
 * 依次插入3个结点\n
 * 打印singly_linked_list\n\n
 * 使用singly_linked_list构造singly_linked_list_2\n
 * 打印singly_linked_list_2\n
 *
 *
 * -------------------
 */
void SingleLinkListTest::TestCopyConstructor() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|             Test SinglyLinkList CopyConstructor           |" << endl;
    cout << "|                   测试-单向链表-复制构造                  |" << endl << endl << endl;

    // 声明singly_linked_list
    SingleLinkedList<string> singly_linked_list;

    // 依次插入3个结点
    singly_linked_list.insertData(1, "Beijing");
    singly_linked_list.insertData(2, "Shanghai");
    singly_linked_list.insertData(3, "Guangzhou");

    // 打印singly_linked_list
    singly_linked_list.print();

    // 使用singly_linked_list构造singly_linked_list_2
    SingleLinkedList<string> singly_linked_list_2 = singly_linked_list;

    // 打印singly_linked_list_2
    singly_linked_list_2.print();

    cout << "-------------------------------------------------------------" << endl << endl;
}


void SingleLinkListTest::TestInsert() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                 Test SinglyLinkList insertData                |" << endl;
    cout << "|                         试单链表插入                        |" << endl << endl << endl;

    auto* singly_linked_list = new SingleLinkedList<int>();

    singly_linked_list->insertData(1, 1);
    singly_linked_list->insertData(2, 2);
    singly_linked_list->insertData(3, 3);

    singly_linked_list->print();

    cout << "-------------------------------------------------------------" << endl << endl;
}


void SingleLinkListTest::TestLength() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                 Test SinglyLinkList getLength                |" << endl;
    cout << "|                        测试单链表长度                       |" << endl << endl << endl;

    auto* singly_linked_list = new SingleLinkedList<int>();

    singly_linked_list->insertData(1, 1);
    singly_linked_list->insertData(2, 2);
    singly_linked_list->insertData(3, 3);

    cout << "链表长度: " << singly_linked_list->getLength() << endl;

    cout << "-------------------------------------------------------------" << endl << endl;
}


/*!
 * @brief **测试-单向链表-删除结点**
 * @note
 * 测试-单向链表-删除结点
 * -------------------
 * -------------------
 *
 * -------------------
 * 声明singly_linked_list\n\n
 * 依次插入5个结点\n
 * 打印singly_linked_list\n\n
 * 执行3次删除, 打印每次删除结点后的singly_linked_list\n
 *
 *
 * -------------------
 */
void SingleLinkListTest::TestRemove() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                 Test SinglyLinkList removeData                |" << endl;
    cout << "|                   测试-单向链表-删除结点                  |" << endl << endl << endl;

    // 声明singly_linked_list
    auto* singly_linked_list = new SingleLinkedList<string>();

    // 依次插入5个结点
    singly_linked_list->insertData(1, "Beijing");
    singly_linked_list->insertData(2, "Shanghai");
    singly_linked_list->insertData(3, "Guangzhou");
    singly_linked_list->insertData(4, "Shenzhen");
    singly_linked_list->insertData(5, "Caoxian");

    // 打印singly_linked_list
    cout << "删除前的链表:" << endl;
    singly_linked_list->print();

    // 执行3次删除, 打印每次删除结点后的singly_linked_list
    cout << "测试删除功能:" << endl;

    string target_str;
    singly_linked_list->removeData(1, target_str);
    singly_linked_list->print();
    singly_linked_list->removeData(4, target_str);
    singly_linked_list->print();
    singly_linked_list->removeData(2, target_str);
    singly_linked_list->print();

    cout << "-------------------------------------------------------------" << endl << endl;
}


/*!
 * @brief **测试-单向链表-清空**
 * @note
 * 测试-单向链表-清空
 * ---------------
 * ---------------
 *
 * ---------------
 * 声明singly_linked_list\n\n
 * 依次插入5个结点\n
 * 打印singly_linked_list\n\n
 * 清空\n
 * 打印singly_linked_list\n
 *
 *
 * ---------------
 */
void SingleLinkListTest::TestClear() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                 Test SinglyLinkList clear                 |" << endl;
    cout << "|                     测试-单向链表-清空                    |" << endl << endl << endl;

    // 声明singly_linked_list
    auto* singly_linked_list = new SingleLinkedList<double>();

    // 依次插入5个结点
    singly_linked_list->insertData(1, 135.34);
    singly_linked_list->insertData(2, 305.43);
    singly_linked_list->insertData(3, 304.83);
    singly_linked_list->insertData(4, 405.31);
    singly_linked_list->insertData(5, 804.54);

    // 打印singly_linked_list
    singly_linked_list->print();

    // 清空
    singly_linked_list->clear();

    // 打印singly_linked_list
    singly_linked_list->print();

    cout << "-------------------------------------------------------------" << endl << endl;
}


void SingleLinkListTest::TestSearch() {

    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                 Test SinglyLinkList search                |" << endl;
    cout << "|                     测试-单向链表-搜索                    |" << endl << endl << endl;

    auto* singly_linked_list = new SingleLinkedList<string>();

    singly_linked_list->insertData(1, "Beijing");
    singly_linked_list->insertData(2, "Shanghai");
    singly_linked_list->insertData(3, "Guangzhou");
    singly_linked_list->insertData(4, "Shenzhen");
    singly_linked_list->insertData(5, "Caoxian");

    LinkNode<string>* bj_node_ptr = singly_linked_list->search("Beijing");
    LinkNode<string>* cx_node_ptr = singly_linked_list->search("Caoxian");

    cout << "bj_node_ptr->data: " << bj_node_ptr->data << endl;
    cout << "cx_node_ptr->data: " << cx_node_ptr->data << endl;

    cout << "-------------------------------------------------------------" << endl << endl;
}


/*!
 * @brief **测试-单向链表-获取结点**
 * @note
 * 测试-单向链表-获取结点
 * -------------------
 * -------------------
 *
 * -------------------
 * 声明city_linked_list\n
 * 依次插入5个城市\n
 * 获取位置1和位置2的城市\n
 * 打印结点信息\n
 *
 *
 * -------------------
 */
void SingleLinkListTest::TestGetNode() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|               Test SingleLinkedList getNode               |" << endl;
    cout << "|                  测试-单向链表-获取结点                   |" << endl << endl << endl;

    // 声明city_linked_list
    auto* city_linked_list = new SingleLinkedList<string>();    // 城市链表city_linked_list

    // 依次插入5个城市
    city_linked_list->insertData(1, "Beijing");     // 位置1插入北京
    city_linked_list->insertData(2, "Shanghai");    // 位置2插入上海
    city_linked_list->insertData(3, "Guangzhou");   // 位置3插入广州
    city_linked_list->insertData(4, "Shenzhen");    // 位置4插入深圳
    city_linked_list->insertData(5, "Caoxian");     // 位置5插入曹县

    // 获取位置1和位置2的城市
    LinkNode<string>* pos_1_node = city_linked_list->getNode(1);
    LinkNode<string>* pos_2_node = city_linked_list->getNode(2);

    // 打印结点信息
    cout << "pos_1_node->data: " << pos_1_node->data << endl;
    cout << "pos_2_node->data: " << pos_2_node->data << endl;

    cout << "-------------------------------------------------------------" << endl << endl;
}


/*!
 * @brief **测试-单向链表-设置和获取数据**
 * @note
 * 测试-单向链表-设置和获取数据
 * ------------------------
 * ------------------------
 *
 * ------------------------
 * 声明singly_linked_list\n
 * 依次插入3个结点\n
 * 获取第2个结点并打印\n
 * 将第2个结点设置成"Shenzhen"\n
 * 打印链表\n
 *
 *
 * ------------------------
 */
void SingleLinkListTest::TestGetDataAndSetData() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|            Test SinglyLinkList GetDataAndSetData          |" << endl;
    cout << "|                测试-单向链表-设置和获取数据               |" << endl << endl << endl;

    // 声明singly_linked_list
    auto* singly_linked_list = new SingleLinkedList<string>();

    // 依次插入3个结点
    singly_linked_list->insertData(1, "Beijing");
    singly_linked_list->insertData(2, "Shanghai");
    singly_linked_list->insertData(3, "Guangzhou");

    // 获取第2个结点并打印
    string city;
    singly_linked_list->getData(2, city);
    cout << city << endl;

    // 将第2个结点设置成"Shenzhen"
    singly_linked_list->setData(2, "Shenzhen");

    // 打印链表
    singly_linked_list->print();


    cout << "-------------------------------------------------------------" << endl << endl;
}